package com.example.myyiyanmengjava.fragment;

import android.os.Bundle;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mvplibrary.ui.fragment.BaseMvpFragment;
import com.example.myyiyanmengjava.R;
import com.example.myyiyanmengjava.adapter.SheetAdapter;
import com.example.myyiyanmengjava.bean.Person;
import com.example.myyiyanmengjava.callback.Mainconcations;
import com.example.myyiyanmengjava.model.HomeModel;
import com.example.myyiyanmengjava.presenter.HomePresenter;

import java.util.ArrayList;

public class SheetFragment<T> extends BaseMvpFragment<Mainconcations.MainView, HomeModel, HomePresenter<T>> implements Mainconcations.MainView<T> {
    private RecyclerView rv_list;
    private String TAG = "朱勇闯fragment";
    private boolean hadIntercept;

    @Override
    protected HomePresenter<T> createPresenter() {
        return new HomePresenter<>();
    }

    @Override
    protected void initEvent() {
        Bundle arguments = getArguments();
        Person person = (Person) arguments.getSerializable("person");
//        Log.e(TAG, "loadData:561564564 " + person.getName());
        ArrayList<Person> people = new ArrayList<>();
        people.add(person);
        rv_list = getView().findViewById(R.id.rv_sheet);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        rv_list.setLayoutManager(linearLayoutManager);
//        Log.e(TAG, "onViewCreated: " + list.get(0).getName());
        SheetAdapter sheetAdapter = new SheetAdapter(people, getActivity(), R.layout.item_sheet);
        rv_list.setAdapter(sheetAdapter);
        sheetAdapter.notifyDataSetChanged();
    }

    @Override
    protected int createLayoutId() {
        return R.layout.fragment_sheet;
    }

    @Override
    public void showList(T t, int type) {

    }

    @Override
    public void showError(String error) {

    }

    @Override
    public void showProgressbar() {

    }

    @Override
    public void hideProgressbar() {

    }

    /* public boolean onBackPressed() {
         if (hadIntercept) {
             return false;
         } else {
             getFragmentManager().popBackStack();
             hadIntercept = true;
             return true;
         }
     }*/
    public boolean onBackPressed() {
// 当确认没有子Fragmnt时可以直接return false
        if (false) {
            Toast.makeText(getActivity(), "重新点击", Toast.LENGTH_SHORT).show();
            return true;
        } else {
            return BackHandlerHelper.handleBackPress(this);
        }
    }
}